<?php

class Core_Agent_Component_Subject_View_Article_Create extends Core_Agent_Share_View_Form {

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(array('state'=>'draft'), 'save')."')");
        $group->addButton($this->__('share.button.submit'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(array('state'=>'pending'), 'save')."')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('content_form')
                ->addHiddenField('id', 'content[id]');
        $form->addTextboxField($this->__('share.label.title'), 'title', 'content[title]', TRUE)
                ->addValidateRule('required');
        $form->addComboTreeField($this->__('article.label.category'), 'category_id', "content[category_id]", TRUE)
                ->bindData($this->getCategory()->toArray(), 0, array('valueKey'=>'id', 'textKey'=>'title', 'parentKey'=>'parent_id', 'childKey'=>'id'));
        $form->addTextboxField($this->__('share.label.sef_url'), 'sef_url', 'content[sef_url]');
        $form->addTextboxField($this->__('article.label.author'), 'author', 'content[author]');
        $form->addDatetimeField($this->__('share.label.start_time'), 'start_time', 'content[start_time]')
                ->setFormat('Y-m-d')
                ->setCurrentDate();
        $form->addDatetimeField($this->__('share.label.end_time'), 'end_time', 'content[end_time]')
                ->setFormat('Y-m-d');
      	$form->addTextboxField($this->__('article.label.resource'), 'resource', 'content[resource]');
        $form->addTextboxField($this->__('share.label.tag'), 'tag', 'content[tag]');
        $form->addBooleanField($this->__('article.label.subject_recommend'), 'is_recommend', 'content[is_recommend]')
                ->setYesOption($this->__('status.boolean.1'))
                ->setNoOption($this->__('status.boolean.0'));
        $form->addBooleanField($this->__('article.label.subject_top'), 'subject_is_top', 'content[subject_is_top]')
                ->setYesOption($this->__('status.boolean.1'))
                ->setNoOption($this->__('status.boolean.0'));
        $form->addFileField($this->__('share.label.preview_image'), 'picture', 'content[picture][]')
                ->setMultiple(TRUE);
                
        $form->addTextareaField($this->__('share.label.introduction'), 'introduction', 'content[introduction]');
        $form->addEditorField('', 'content', 'content[content]');
        $form->createTab('base_option', $this->__('article.label.base_option'),
                array('field_title', 'field_category_id', 'field_sef_url', 'field_author', 'field_resource', 'field_tag', 'field_introduction'));
        $form->createTab('content_option', $this->__('article.label.content'), array('field_content'));
        $form->createTab('picture_option', $this->__('article.label.picture_option'), array('field_picture'));
        $form->createTab('display_option', $this->__('article.label.display_option'),
                array('field_start_time', 'field_end_time','field_is_recommend','field_subject_is_top'));
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
            $form->getInput('picture')
				 ->setBaseUrl($this->getRouter()->getBaseUrl().'pub/article/content/'.$entity->getId().'/');
            if(!empty($entity['picture'])){
                $form->getInput('picture')->setValue(explode(',', $entity->getPicture()));
            }
        }
        parent::buildForm($form);
    }

}